import type { UniRouteType } from "./type"

/** 路由跳转方式 */
export const uniJumpWay = {
  'navigateBack': (config?: UniRouteType['navigateBack']) => {
    // #ifdef H5
    const delta = (config?.delta ?? 0) * -1
    history.go(delta || -1)
    config?.success?.({})
    // #endif
    // #ifndef H5
    uni.navigateBack(config)
    // #endif
  },
  'navigateTo': uni.navigateTo,
  'reLaunch': uni.reLaunch,
  'redirectTo': uni.redirectTo,
  'switchTab': uni.switchTab,
}

/** 枚举固定字符串 */
export enum ConstString {
}

/** 系统参数 */
export enum SysKey {

}

/** 字典 */
export enum DictKey {

}

/** 服务端状态码 */
export enum ServiceStatusCode {
  /** 登录过期 */
  LoginExpired = 424,
  /** 服务器异常 */
  ServiceErr = 500,
  /** 请求成功 */
  SuccessCode = 0
}

/** 日期格式 */
export enum DateFormat {
  year = 'YYYY',
  month = 'MM',
  day = 'DD',
  hour = 'HH',
  minute = 'mm',
  second = 'ss',
  date = `${year}-${month}-${day}`,
  time = `${hour}:${minute}:${second}`,
  datetime = date + ' ' + time
}

/** 时间戳 */
export enum DateNow {
  second = 1000,
  minute = 60 * second,
  hour = minute * 60,
  day = hour * 24,
  month = day * 30,
  year = day * 365
}

export namespace ValidateRegExp {
  export const id = /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/
  export const phone = /1[3-9]\d{9}/
  export const walletAddress = new RegExp(`^0x[A-Za-z\\d]{40}$`)
  export const email = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
}